<%--
 *  File:    OutPeriodDataDetail.jsp
 *  @Author: Jamesli
 *  Date:    2010/7/29
 *
 *  Copyright (C) 2000 - 2010 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java"%>
<%@ page import="java.util.*"%>
<%@ page import="org.apache.log4j.Category"%>

<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom"%>

<%//init param
	String privilegeCode = "E0215";
	String strModuleName = "CM";
	String contextPath = request.getContextPath();
%>

<%//--------------------------------------  include files list --%>

<%@ include file="/inc/FrmDefault.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>


<html>
<head>
<title>OutPeriodDataDetail</title>
<PageFlow:CheckPageFlow pageName="p_outperioddatadetail"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/ScriptLib.js"></script>
<%@ include file="/inc/SummaryDivision.inc"%>
<script>
function page_checkall(){
	var allcheck = cform.checkall;
	var details = document.getElementsByName("detailids");
	for(var i = 0 ; i < details.length;i++){
		details[i].checked = allcheck.checked;
	}
}

function page_uncheckall(element){
	if(!element.checked)cform.checkall.checked = false;
}

function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  if(!editform) return;
  editform.action = "OutPeriodDataDetail.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();
}

function page_back(){
	var processtype = cform.processtype.value;
	var datafrequency = cform.datafrequency.value;
	if(processtype == '' || processtype == -1){
		processtype = 10;
	}
	self.location.href='<%=contextPath %>/phap/phap.datp/masterdata/cm/dataclean/OutPeriodDataSummary.jsp?<%= OvalTools.randomURL() %>&processtype=' + processtype + '&datafrequency=' + datafrequency;
}

function page_delete(){
	var details = document.getElementsByName("detailids");
	var checkflag = false;
	for(var i = 0 ; i < details.length; i++){
		if(details[i].checked){
			checkflag = true;
			break;
		} 
	}
	if(!checkflag){
		alert("<%= message.getMessageDesc("PLEASE_SELECT")%>");
		return;
	}
	if(!confirm("<%= message.getMessageDesc("ARE_YOU_SURE_DEL")%>")) return;
	cform.actionname.value = "update";
	cform.issupply.value = "N";
	cform.target = "_self";
	isRunning = true;
	cform.submit();
}

function page_deleteall(){
	if(!confirm("<%= message.getMessageDesc("ARE_YOU_SURE")%>")) return;
	cform.actionname.value = "allupdate";
	cform.issupply.value = "N";
	cform.target = "_self";
	isRunning = true;
	cform.submit();
}

function page_addon(){
	var enddate = document.cform.enddate.value;
	var thedate = document.getElementsByName("thedate");
	if(enddate == ""){
		alert("<%= message.getMessageDesc("DT_NO_OPENED_PERIOD_CANT_ADDON")%>");
		return;
	}
	var details = document.getElementsByName("detailids");
	var checkflag = false;
	for(var i = 0 ; i < details.length; i++){
		if(details[i].checked){
			if(thedate[i].value > enddate){
				alert("<%= message.getMessageDesc("TIME_BEYOND_PERIOD_CANT_ADDON")%>");
				return;
			}
			checkflag = true;
		} 
	}
	if(!checkflag){
		alert("<%= message.getMessageDesc("PLEASE_SELECT")%>");
		return;
	}
	if(!confirm("<%= message.getMessageDesc("ARE_YOU_SURE_ADDON")%>")) return;
	cform.actionname.value = "update";
	cform.issupply.value = "Y";
	cform.target = "_self";
	isRunning = true;
	cform.submit();
}
</script>
</head>

<bod>
<form name="cform" method="post" action="<%=contextPath %>/Dispatcher" target="_parent">
	<input type="hidden" name="pagename" value="p_outperioddatadetail"> 
	<input type="hidden" name="actionname"> 
	<custom:hidden property="fileid"/>
	<custom:hidden property="processtype"/>
	<custom:hidden property="datafrequency"/>
	<input type="hidden" name="issupply">
	<custom:hidden property="enddate" name="orgperioddetail" dataType="date" dataFormat="yyyy-MM-dd"/>
<%@ include file="/inc/PageLocation.inc" %>
<%
	Integer processtype = (Integer)pageContext.getAttribute("processtype");
	String datafrequency = (String)pageContext.getAttribute("datafrequency");
%>
<table width="100%" cellspacing="0" border="0" cellpadding="0">
	<tr>
		<td class="summary_top"></td>
	</tr>
	<tr>
		<td>
		<table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0">
		<tr class="deepblue-left"> 
		  <td width="5%" class="title_center">
		  	<custom:checkbox property="checkall" onclick="page_checkall()" styleClass="checkbox"/>
		  </td>
          <td width="18%" class="title_center"><%= label.getLabelName("L_Dealer") %></td>
          <%if(processtype.intValue() != 20){ %>
          <td width="*%" class="title_center"><%if(processtype.intValue() == 10){%><%= label.getLabelName("L_Customer") %><%}else{ %><%= label.getLabelName("L_Vendor") %><%} %></td>
          <td width="8%" class="title_center"><%= processtype.intValue() == 10?label.getLabelName("L_ComBuyer") + label.getLabelName("L_Province"):label.getLabelName("L_Vendor") + label.getLabelName("L_Province")%></td>
          <td width="8%" class="title_center"><%= processtype.intValue() == 10?label.getLabelName("L_ComBuyer") + label.getLabelName("L_City"):label.getLabelName("L_Vendor") + label.getLabelName("L_City")%></td>
          <td width="8%" class="title_center"><%= processtype.intValue() == 10?label.getLabelName("L_ComBuyer") + label.getLabelName("L_County"):label.getLabelName("L_Vendor") + label.getLabelName("L_County")%></td>
          <% }%>
          <td width="6%" class="title_center"><%= label.getLabelName("L_Prodcode1")%></td>
          <td width="15%" class="title_center"><%= label.getLabelName("L_ProdName")%></td>
          <td width="5%" class="title_center"><%= label.getLabelName("L_Quantity")%></td>
          <td width="5%" class="title_center"><%= label.getLabelName("L_Spec")%></td>
          <td width="8%" class="title_center">
          	<%if(processtype.intValue() == 10){%><%=label.getLabelName("L_SalesDate") %><%}else if(processtype.intValue() == 20){%><%=label.getLabelName("L_InvDate") %><%}else{%><%=label.getLabelName("L_PurchaseDate") %><%}%>
          </td>
        </tr>
        
        <%
	        int i = 0;
	        String strClassType = new String();   

        	Vector totalsummary = (Vector)pageContext.getAttribute("totalsummary");
        	if(totalsummary == null) totalsummary = new Vector();
        %>
        <logic:iterate id="summary" collection="<%= totalsummary %>">                      
        <% 
	        if(i%2 == 1)
	          	strClassType = "td-listrom";
	        else                    
	          	strClassType = "none";
	        i++;     
         %>           
        <tr class="<%= strClassType %>" onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%= strClassType %>'" >
        	<td class="td_center"><custom:checkbox property="originaldataid" changedName="detailids" name="summary" onclick="page_uncheckall(this)" styleClass="checkbox"/></td>
            <td>&nbsp;<custom:write property="dtname" name="summary" nbsp="true"/></td>
            <%if(processtype.intValue() != 20){ %>
            <td>&nbsp;<custom:write property="partnername" name="summary" nbsp="true"/></td>
            <td>&nbsp;<custom:write property="regionname" name="summary" nbsp="true"/></td>
            <td>&nbsp;<custom:write property="cityname" name="summary" nbsp="true"/></td>
            <td>&nbsp;<custom:write property="countyname" name="summary" nbsp="true"/></td>
            <% }%>
            <td>&nbsp;<custom:write property="prodcode" name="summary" nbsp="true"/></td>
            <td>&nbsp;<custom:write property="prodname" name="summary" nbsp="true"/></td>
            <td>&nbsp;<custom:write property="qty" name="summary" nbsp="true"/></td>
            <td>&nbsp;<custom:write property="spec" name="summary" nbsp="true"/></td>
            <td>&nbsp;<custom:write property="thedate" dataType="date" dataFormat="yyyy-MM-dd" name="summary" nbsp="true"/></td>
            <custom:hidden property="thedate" dataType="date" dataFormat="yyyy-MM-dd" name="summary"/>
        </tr>
        </logic:iterate>  
     <%@ include file="/inc/SummaryAction.inc" %>
		</table>
		<%//--------------------------------------  page operation button --%>
		<table width="100%" cellspacing="0" cellpadding="0">
			<tr>
				<td class="summary_top"></td>
			</tr>
			<tr>
				<td class="td_center">
					<%if(i != 0){ %>
					<a onclick="page_deleteall()"><custom:button type="1" label="L_DeleteAll" imgsrc="finish.gif" border="0" style="width:60" /></a>
					<a onclick="page_delete()"><custom:button type="1" label="L_Delete" imgsrc="finish.gif" border="0" style="width:60" /></a>
						<%if("M".equals(datafrequency)) {%>
							<a onclick="page_addon()"><custom:button type="1" label="L_AddOns" imgsrc="finish.gif" border="0" style="width:60" /></a>
						<%} %>
					<%} %>
					<a onclick="page_back()"><custom:button type="1" label="L_Back" imgsrc="finish.gif" border="0" style="width:60" /></a>
				</td>
			</tr>
		</table>
		</td>
	</tr>
</table>
</form>
</body>
</html>



